package com.yangquan.job;


import com.yangquan.service.HellowService;
import com.yangquan.util.SpringContextJobUtil;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class MyJob2 extends QuartzJobBean {
    @Autowired
    HellowService hellowService;

    public HellowService getHellowService() {
        return hellowService;
    }

    public void setHellowService(HellowService hellowService) {
        this.hellowService = hellowService;
    }


    //项目启动就会执行该方法
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
//        hellowService = (HellowService) SpringContextJobUtil.getBean("hellowService");
//        hellowService = (HellowService) SpringContextJobUtil.getBean(HellowService.class);

        //注意该方法无法将service对象进行注入进来,需要以下方式进行获取service对象
        hellowService = SpringContextJobUtil.getBean(HellowService.class);
        hellowService.sayHellow();
    }


}



